package com.qq.mobilemanager.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.qq.mobilesafe.R;
import com.qq.mobilesafe.service.killProcessService;
import com.qq.mobilesafe.utils.SharedPreferencesUtils;
import com.qq.mobilesafe.utils.SystemInfoUtils;

public class TaskManagerSettingActivity extends Activity {
	@ViewInject(R.id.cb_progress_status)
	private CheckBox cb_status;
	
	@ViewInject(R.id.cb_killprogress)
	private CheckBox cb_killprogress;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_task_manager_setting);
		ViewUtils.inject(this);
		initView();
	}
	
	@Override
	protected void onStart() {
		super.onStart();
		if (SystemInfoUtils.isServiceRunning(this, "com.qq.mobilesafe.services.KillProcessService")) {
			cb_killprogress.setChecked(true);
		}else {
			cb_killprogress.setChecked(false);
		}
	}

	private void initView() {
		cb_status.setChecked(SharedPreferencesUtils.getBoolean(
				TaskManagerSettingActivity.this, "is_system_show", false));
		cb_status.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				SharedPreferencesUtils
						.saveBoolean(TaskManagerSettingActivity.this,
								"is_system_show", isChecked);
			}
		});
		
		 final Intent intent = new Intent(this,killProcessService.class);
		cb_killprogress.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					startService(intent);
				}else {
					stopService(intent);
				}
			}
		});

	}
}
